/*
*			Êý¾Ý´¦Àí²ßÂÔÀà
*/

#pragma once

#include "CxType.h"
#include "CxPort.h"
#include "CxLinerBuffer.h"


namespace cv{class Mat;}

BEGIN_NAMESPACE(DataRevPart)

using cv::Mat;



struct ImageHeader
{
	int		_col;
	int		_row;
	short	_type;
	ULONG	size;		//Ñ¹ËõÍ¼Ïñ´óÐ¡£¬·ÇÊµ¼Ê´óÐ¡
};

class CxDataHandle 
{
public:
	CxDataHandle(){}
	virtual		~CxDataHandle(){}
public:
	virtual		void	ConnectedSlot(CxPort *,size_t no)=0;
	virtual		void	CombineMat(CxPort *,CxLinerBuffer *)=0;
};



class	CxDataHandle_R	: public CxDataHandle
{
public:
	CxDataHandle_R(){}
	~CxDataHandle_R(){}
public:

	void	ConnectedSlot(CxPort *,size_t no);
	void	CombineMat(CxPort *,CxLinerBuffer *);

private:
	//¼¯³ÉÊý¾Ý½âÑ¹Ëõ£¬´ò°üÍ¼Æ¬
	BYTE	*Uncompress(BYTE * ,ULONG &);
	Mat		CombineMat(BYTE *,ULONG size,int  _row,int  _col,short type);
	void	ClearPort(CxPort *port);
	void	RevFunc(const ERRCODE &,size_t rtsize,CxPort *port,
					BYTE *data,ImageHeader imagehead,CxLinerBuffer *);

	static const BYTE REVDATA[];

private:
	boost::mutex					_mu;
	boost::condition_variable_any	_cond;

};


//Implement version 2
class CxDataHandle_W	:	public  CxDataHandle 
{
public:
	CxDataHandle_W(){}
	~CxDataHandle_W(){}

public:

	void	ConnectedSlot(CxPort *,size_t no);
	void	CombineMat(CxPort *,CxLinerBuffer *);


private:

	void	CombineMat_thread(CxLinerBuffer *,ImageHeader ,BYTE *);

	BYTE*	Uncompress(BYTE *,ULONG& );
};



END_NAMESPACE
